package com.shenzhen.group.common.strategy;

import com.shenzhen.group.common.player.Player;

import java.math.BigDecimal;
import java.util.Random;

/**
 * 押钱策略
 * @author 周赛波
 * @version v1.0.0
 * @date 2021/12/26 12:31
 */
public class InvestStrategy {
    /** 已玩次数 */
    private int number;
    /** 上次压的钱 */
    private BigDecimal lastAmt;
    /** 连续输钱或赢钱次数 TODO 有问题 */
    private int continueNum;

    public BigDecimal avgStrategy(Player player) {
        lastAmt = player.getBalance().divide(new BigDecimal(20), 2, 4);
        number++;
        return lastAmt;
    }

    public BigDecimal fluctuateStrategy(Player player) {
        BigDecimal res;
        switch (continueNum / 3) {
            case 0:
                res = player.getBalance().divide(new BigDecimal(100), 2, 4);
                continueNum++;
                break;
            case 1:
                res = player.getBalance().divide(new BigDecimal(500), 2, 4);
                continueNum++;
                break;
            case 2:
                res = res = player.getBalance().divide(new BigDecimal(1000), 2, 4);
                continueNum++;
                break;
            case -1:
                res = player.getBalance().divide(new BigDecimal(20), 2, 4);
                continueNum--;
                break;
            case -2:
                res = player.getBalance().divide(new BigDecimal(2), 2, 4);
                continueNum--;
                break;
            default:
                if (continueNum < 0) {
                    res = player.getBalance();
                    continueNum--;
                } else {
                    res = player.getBalance().divide(new BigDecimal(10000), 2, 4);
                    continueNum++;
                }
        }
        return res;
    }

    public BigDecimal RandomStrategy(Player player, int part) {
        Random r = new Random();
        BigDecimal divide = player.getBalance().divide(new BigDecimal(part), 0, 4);
        return new BigDecimal(r.nextInt(Math.abs(divide.intValue() - 1)) + 1);
    }

    public BigDecimal smallRandomStrategy(int upper, int lower) {
        Random r = new Random();
        return new BigDecimal(r.nextInt(upper - lower) + lower);
    }

    public BigDecimal paragraphStrategy(Player player) {
        BigDecimal res;
        if (number % 2 == 0) {
            res = player.getBalance();
        }
        res = player.getBalance().divide(new BigDecimal(1000), 2, 4);
        number++;
        return res;
    }

}
